/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.system.domain;

import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import io.swagger.annotations.ApiModelProperty;
import cn.hutool.core.bean.copier.CopyOptions;
import javax.persistence.*;
import javax.validation.constraints.*;
import java.sql.Timestamp;
import java.io.Serializable;
import java.util.List;

/**
* @website https://el-admin.vip
* @description /
* @author whj
* @date 2021-06-03
**/
@Entity
@Data
@Table(name="task")
public class Task implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    @ApiModelProperty(value = "id")
    private Long id;

    @Column(name = "task_name")
    private String taskName;

    @Column(name = "json_path")
    @ApiModelProperty(value = "jsonPath")
    private String jsonPath;

    @Column(name = "weight",nullable = false)
    @NotNull
    @ApiModelProperty(value = "weight")
    private Long weight;

    @Column(name = "json_count")
    @ApiModelProperty(value = "jsonCount")
    private Long jsonCount;

    @Column(name = "submit_time")
    @ApiModelProperty(value = "submitTime")
    private Timestamp submitTime;

    @Column(name = "status")
    @ApiModelProperty(value = "status")
    private Long status;

    @Column(name = "finish_time")
    @ApiModelProperty(value = "finishTime")
    private Timestamp finishTime;

    @Column(name = "finished_count")
    @ApiModelProperty(value = "finishedCount")
    private Long finishedCount;

    @Column(name = "remaining_count")
    @ApiModelProperty(value = "remainingCount")
    private Long remainingCount;

    @Column(name = "result_path")
    @ApiModelProperty(value = "resultPath")
    private String resultPath;

    @Column(name = "force_update")
    @ApiModelProperty(value = "forceUpdate")
    private Long forceUpdate;

    @Column(name = "save_result_image")
    @ApiModelProperty(value = "0不保存识别结果图片/1保存识别结果图片")
    private Long saveResultImage;

    @ManyToMany
    @JoinTable(name = "file_task",
            joinColumns = {@JoinColumn(name = "task_id",referencedColumnName = "id")},
            inverseJoinColumns = {@JoinColumn(name = "file_id",referencedColumnName = "id")})
    @ApiModelProperty(value = "所属用户")
    private List<FileDetail> fileDetails;

    public void copy(Task source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
}